We take the example that we have used in the very first experiment. The goal of this experiment is to generate an images which only contains the colors of the original image. In the context of our machine learning problem, we want to generate the labels for the images. Another way to think about this is that we are generating image masks, when we are talking about image segmentation.
from plotly.figure_factory._ternary_contour import create_ternary_contour
import numpy as np
Al = np.array([0.0, 0.0, 0.0, 0.0, 1.0 / 3, 1.0 / 3, 1.0 / 3, 2.0 / 3, 2.0 / 3, 1.0])
Cu = np.array([0.0, 1.0 / 3, 2.0 / 3, 1.0, 0.0, 1.0 / 3, 2.0 / 3, 0.0, 1.0 / 3, 0.0])
Y = 1 - Al - Cu
# synthetic data for mixing enthalpy
# See https://pycalphad.org/docs/latest/examples/TernaryExamples.html
enthalpy = (Al - 0.01) * Cu * (Al - 0.52) * (Cu - 0.48) * (Y - 1) ** 2
fig = create_ternary_contour(
np.array([Al, Y, Cu]),
enthalpy,
pole_labels=["", "", ""],
interp_mode="cartesian",
)
fig.show()
We define the layout dictionary for the plotly plots. This dictionary sets the relevant parameters for our use case. Specifically, we remove the grid, ticks, and background color. Note that we also set the line width to 1. Ideally, we would like to have a line width of 1, but for some reason a blue line is still visible when we set the line width to 0. Therefore, we set the line width to 1.
layout_dict = dict(
ternary=dict(
aaxis=dict(
showgrid=False,
ticks="",
tickmode="array",
tickvals=[],
linewidth=1,
color="rgba(0,0,0,0)",
),
baxis=dict(
showgrid=False,
ticks="",
tickmode="array",
tickvals=[],
linewidth=1,
color="rgba(0,0,0,0)",
),
caxis=dict(
showgrid=False,
ticks="",
tickmode="array",
tickvals=[],
linewidth=1,
color="rgba(0,0,0,0)",
),
bgcolor="rgba(0,0,0,0)",
),
paper_bgcolor="rgba(0,0,0,0)",
)
fig.update_layout(layout_dict)
fig.show()
As you can see in the plot above, the lines are still visible. We can remove the lines by setting the line width to 0 and setting the color to a transparent color. For some reason, this does work for the remaining lines visible in the plot.
ternary_dict = dict(line=dict(color="rgba(0,0,0,0)", width=0))
fig.update_traces(ternary_dict)
fig.show()
We end up with an image that only contains the colors of the original image. This is exactly what we wanted to achieve. However, the dimensions of the image may not be the same as the original image. Due to the fact that we defined a line width of 1 in the layout. This has to be manually confirmed. We do want the images to have the same dimensions as the original images. So, if they do not have the same dimensions, we have to manually adjust the dimensions of the images. Or find another way to generate the labels for the images.